/*
 * Copyright 2012 Gayan Perera
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/
package gap.maven.script.helpers;


import java.io.IOException;

import org.apache.maven.plugin.logging.Log;

/**
 * The linker implementation which uses the mklink command on windows vista/7/2008 operating systems.
 * 
 * @author gayan.perera
 *
 */
public class MKLLinker extends AbstractLinker {

    public MKLLinker(Log logger) {
        super(logger);
    }

    @Override
    protected void performLinking(String sourcePath, String targetPath) throws IOException {
        try {
            // TODO: check for return values.
            String[] command = new String[5];
            command[0] = "cmd.exe";
            command[1] = "/c";
            command[2] = "mklink";
            command[3] = targetPath;
            command[4] = sourcePath;
            Process process = Runtime.getRuntime().exec(command);
            process.waitFor();
            
            printCommandOutput(process.getInputStream(), process.getErrorStream());
        } catch (InterruptedException ex) {
            throw new IOException("Command didn't complete.", ex);
        }
    }
}
